//////////////////////////////////////////////////////////////////////
// (c) 2003-2010 sonofdelphi
// MIT License
//////////////////////////////////////////////////////////////////////

#include<vector>
#include<string>

class CHelper;

class CArgumentParser
{
public:
	bool	isValidOption(char cOption);//To check whether an option is valid or not
	int		parse(int& optc, char **argv);//Parse the command line
	bool	wasParseSuccessful();//Returns result of parse-attempt 
	bool	wasOptionSupplied(char cOption);//Returns whether option was supplied
	char*	getField(char cOption, int nCardinal=0);//Returns string supplied for option
	int		getFieldCardinal(char cOption);
	void	fillHelpForOption(char cOption, char* strValue);

	CHelper* m_Helper;		//Help-related functionality

	CArgumentParser(char* strSyntax);//To initialize with syntax
	virtual ~CArgumentParser();//Destructor to take care of deallocation

protected:
	bool	m_bWasParseSuccess;//Did operate result in a valid-parse
	bool	m_bIsInOptionMode;
	bool	m_bWasThereMoreToFill;

	char*	m_sSyntax;		//Syntax of the options
	char*	m_sSyntaxWorkingCopy; //Working copy of syntax, modified during parse
	bool*	m_abSupplied; //Working copy of syntax, modified during parse

	int		m_nOptions;			//Number of options

	char*	m_sOption;		//Stores the options 
	std::vector<std::vector<std::string> >	m_asValue;		//Stores the value for the options

	static const char cArgumentSpecifier;	//Character which specifies value essential in syntax
	static const char cOptionPrefix;		//Character which WILL be followed by an option
	
protected:
	bool	isValueEssentialForOption(char cOption);//Checks whether option takes a value
	int		indexOfOption(char c);//Returns index of the option
	void	invalidateOption(char c);//Marks the option as used by removing it from working copy of syntax
	char*	getField(int nPos, char& cOption, int nSeq=0);//Returns value in nPos position
	void	fillValueForOption(char cOption, char *strValue);//Fills the value for option
};

